package com.springboot.repository;

import com.springboot.domain.BtPerson;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public interface PersonRepository extends JpaRepository<BtPerson, String> {

    @Modifying
    @Query("update BtPerson bp set bp.status = '4' where bp.id = ?1")
    void logout(String userId);

    Page<BtPerson> findByStatus(String status, Pageable pageable);

    @Query("select bp from BtPerson bp,BtUser bu where bp.id=bu.userId and bp.status='2' and bp.name like concat('%',?1,'%') " +
            "and bu.userName like concat('%',?2,'%') and bp.province like concat ('%',?3,'%') and bp.profession like concat('%',?4,'%') ")
    List<BtPerson> findByFuzzyQuery(String realName,String name,String province,String profession);

    @Modifying
    @Query("update BtPerson bp set bp.views = ?1 where bp.id = ?2 ")
    void addViews(int views,String id);

    @Query("select bp from BtPerson bp where bp.name like concat('%',?1,'%') and bp.status = '2'")
    List<BtPerson> findPerson(String name);
}
